<template>
  <div class="bg">
    <div style="width: 450px; background-color: #eaefff; padding: 40px 20px; opacity: 0.9; border-radius: 5px;box-shadow: 0 0 10px rgba(0,0,0,0.1)">
      <el-form status-icon ref="formRef" :model="data.form" :rules="data.rules">
        <div style="text-align: center;font-weight: bold;font-size: 24px;margin-bottom: 40px;">欢 迎 注 册</div>
      <el-form-item prop="username" >
        <el-input size="large" placeholder="请输入账号" v-model="data.form.username" autocomplete="off" prefix-icon="User"/>
      </el-form-item>
        <el-form-item prop="password" >
          <el-input size="large" show-password placeholder="请输入密码" v-model="data.form.password" autocomplete="off" prefix-icon="Lock"/>
        </el-form-item>
        <el-form-item prop="confirmPassword" >
          <el-input size="large" show-password placeholder="请再次输入密码" v-model="data.form.confirmPassword" autocomplete="off" prefix-icon="Lock"/>
        </el-form-item>
      </el-form>
      <div style="margin-bottom: 20px;">
        <el-button style="width: 100%" size="large" type="primary" @click="login">注 册</el-button>
      </div>
      <div style="text-align: right;">
        已有账号？请<a style="color: #409EFF" href="/login">登录</a>
      </div>
    </div>
  </div>
</template>
<script setup>
import {reactive,ref} from "vue";
// import request from "@/utils/request.js";
import router from "@/router/index.js";
const formRef= ref()
const validatePass = (rule, value, callback) => {
  // 校验两次输入的密码是否一致 value 为用户输入的密码
  if (value !== data.form.password) {
    callback(new Error('两次输入密码不一致!'));
  } else {
    callback();
  }
};
const data = reactive({
  form:{},
  rules:{
    username: [
      { required: true, message: '请输入账号', trigger: 'blur' },
      { min: 3, max: 12, message: '长度在 3 到 12 个字符', trigger: 'blur' }
    ],
    password: [
      { required: true, message: '请输入密码', trigger: 'blur' },
      // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
   ],
    confirmPassword: [
      {required: true, message: '请再次确认密码', trigger: 'blur'},
      { validator: validatePass, trigger: 'blur' },
      // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
    ]
  }
})
const login = () =>{
  formRef.value.validate((valid) => {
    if (valid) {
      // request.post('/register',data.form).then(res =>{
      //   if(res.code === '200'){
      //     ElMessage.success('注册成功')
      //     router.push('/login')
      //   }else {
      //     ElMessage.error(res.msg)
      //   }
      // })
    }
  });

}


</script>
<style scoped>
.bg{
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background-image: url("@/assets/imgs/bj2.jpg");
  background-size: cover;
}
</style>